package com.zsl.controller.Admin;

import com.alibaba.fastjson.JSON;
import com.zsl.service.OrderInfoService;
import com.zsl.service.impl.OrderInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "OpOrderStatus",urlPatterns = "/op/order/status")
public class OpOrderStatus extends HttpServlet {
    OrderInfoService orderInfoService=new OrderInfoServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        Map<String, Object> res = new HashMap<>();
        //获取数据
        String orderId = request.getParameter("orderId").equals("") ? null : request.getParameter("orderId");
        String des_status = request.getParameter("des_status").equals("") ? null : request.getParameter("des_status");
        //输入为空时
        if(orderId==null || des_status==null){
            res.put("code","0");
            res.put("line","0");
            res.put("msg","参数错误");
            return;
        }
        try {
            res=orderInfoService.updateOrderInfoStatus(orderId,des_status);
        } catch (Exception throwables) {
            throwables.printStackTrace();
            res.put("code","0");
            res.put("line","0");
            res.put("msg","内部出错");
        }finally {
            PrintWriter out = response.getWriter();
            out.write(JSON.toJSONString(res));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
